<?php

class CS_Config_Xml extends CS_Config {

	public $content;

	public function __construct($xml = null)
	{
		if(!empty($xml))
		{
			$this->loadConfig($xml);
		}
	}

	public function loadConfig($xml = null)
	{
		if(is_file($xml))
		{
			$this->content = simplexml_load_file($xml);
		} else {
			$this->content = simplexml_load_string($xml);
		}

		if(!empty($this->content))
		{
			if(isset($this->content->database) && !empty($this->content->database))
			{
				// write database configuration
				if(trim((string)$this->content->database) == 'false')
				{
					CS_Config::write('Database', false);
				} else {
					// TODO: allow multiple databse configurations
					CS_Config::write('Database', (array)$this->content->database->default);
				}
			}
		}
	}
}
